package com.abiao.shop.controller;

import com.abiao.shop.pojo.User;
import com.abiao.shop.result.CodeMsg;
import com.abiao.shop.result.Result;
import com.abiao.shop.service.OrderService;
import com.abiao.shop.vojo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Description: OrderController    订单模块控制类
 * @Author: AB
 * @Date: 2021-07-20
 * @Version:v1.0
 */
@Controller
public class OrderController {

    @Autowired
    OrderService orderService;

    //获取订单列表
    @RequestMapping("/to_order_list")
    @ResponseBody
    public Result<?> getOrderList(User user){
        List<OrderVo> orders = orderService.getUserAllOrders(user);
        if (orders != null && orders.size() > 0){
            return Result.success(orders);
        }else {
            return Result.error(CodeMsg.ORDER_EMPTY);
        }
    }

    //模拟支付订单
    @RequestMapping("/pay_order/{orderId}")
    @ResponseBody
    public Result<?> payOrder(@PathVariable("orderId")long orderId, User user){
        orderService.payOrder(orderId);
        return Result.success(user);
    }
}
